//
//  DSPassCelebrateView.m
//  DSJY
//
//  Created by lx on 16/12/20.
//  Copyright © 2016年 dsjy. All rights reserved.
//

#import "DSPassCelebrateView.h"
#import "UIView+Extension.h"
#import "DSPassCelebrateCollectionCell.h"
#import "XCYAudioTool.h"

const CGFloat margin = 15;
const CGFloat celebrateW = 125;
const CGFloat celebrateCount = 3;
const CGFloat celebrateH = PassCelebrateViewH / celebrateCount;
#define PassCelebrateCellID  @"PassCelebrateCellID"
@interface DSPassCelebrateView ()
//collectionView
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@end

@implementation DSPassCelebrateView

#pragma mark - 系统回调
+ (instancetype)passCelebrateView
{
    return [[[NSBundle mainBundle] loadNibNamed:@"DSPassCelebrateView" owner:nil options:nil] lastObject];
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    //设置UI
    [self setupUI];
}

#pragma mark - 设置UI
- (void)setupUI
{
    UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)[self.collectionView collectionViewLayout];
    layout.itemSize = CGSizeMake(celebrateW, celebrateH);
    self.collectionView.contentInset = UIEdgeInsetsMake(0, margin, 0, margin);
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"DSPassCelebrateCollectionCell" bundle:nil] forCellWithReuseIdentifier:PassCelebrateCellID];
}

#pragma mark - <UICollectionViewDataSource>
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return ((self.collectionView.width - margin * 2) / celebrateW) * celebrateCount;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    DSPassCelebrateCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:PassCelebrateCellID forIndexPath:indexPath];
    return cell;

}

@end
